#ifndef FARMMANAGEMENTWIDGET_H
#define FARMMANAGEMENTWIDGET_H

#include <QWidget>
#include <QLabel>
#include <QVBoxLayout>
#include <QFrame>
#include <QSqlTableModel>
#include <QGridLayout>
#include <QLineEdit>
#include <QPushButton>
#include <QComboBox>
#include <QScrollArea>
#include "envcard.h"

class FarmCard;

class FarmManagementWidget : public QWidget
{
    Q_OBJECT
public:
    explicit FarmManagementWidget(QWidget *parent = nullptr);
    void refreshFarmList();
signals:
    void farmSelected(int farmId); // 农场选择信号
private slots:
    void onSearchTextChanged(const QString &text);
    void onFarmCardClicked(int farmId);
   // void onAddFarmClicked();
     void onStatusFilterChanged();

private:
    void setupUI();
    void loadFarmData();
    void createFarmCards();
    void clearFarmCards();

    QSqlTableModel *farmModel;
        QList<FarmCard*> farmCards;
        int selectedFarmId = -1;

        // UI 组件
        QLabel *titleLabel;
        QLineEdit *searchEdit;
        QComboBox *statusFilter;
       // QPushButton *addFarmButton;
        QGridLayout *cardsLayout;
        QWidget *cardsContainer;
        QScrollArea *scrollArea;
};

// 农场卡片类
class FarmCard : public QFrame
{
    Q_OBJECT

public:
    explicit FarmCard(int farmId, const QString &description,
                     const QString &videoAddress, int status,
                     QWidget *parent = nullptr);

    int getFarmId() const { return farmId; }
    void setSelected(bool selected);

signals:
    void clicked(int farmId);

protected:
    void mousePressEvent(QMouseEvent *event) override;

private:
    int farmId;
    QLabel *idLabel;
    QLabel *descLabel;
    QLabel *statusLabel;
};

#endif // FARMMANAGEMENTWIDGET_H
